import axios from 'axios'
import {ElMessage} from 'element-plus'
const defaulterror=()=>ElMessage.error('发生了一些错误，请联系管理员！')

function post(url,data,success,failure,error=defaulterror){
axios.post(url,data,{
headers:{
'Content-type':'application/x-www-form-urlencoded'
},
withCredentials: true,
}).then(({data})=>{
if(data.success){
success(data.message)}else {failure(data.message)}
}).catch(error)
}
function get(url,success,failure,error=defaulterror){
axios.get(url,{
withCredentials: true
}).then(({data})=>{
if(data.success)
success(data.message)
else failure(data.status,data.message)
}).catch(error)
}
//前端采用export.default，在写后端代码时用module.export
export {get,post}